#include "../include/head.h"

//写入用户文件
void user_write_file(PUserNode head){
    FILE *file = fopen("./goods_management/data/users.txt","wb");
    if (!file) {
        return;
    }

    PUserNode p = head->next;
    while (p != head) {
        fwrite(&p->info, sizeof(users), 1, file);
        p = p->next;
    }
    fclose(file);
}

//读取用户文件
void user_read_file(PUserNode head){
    FILE *file = fopen("./goods_management/data/users.txt", "rb");
    if (!file) {
        return;
    }

    users data;
    while (fread(&data, sizeof(users), 1, file) == 1) {
        user_tail_insert(head, data);
    }
    fclose(file);
}

//输出用户信息
void output_user_info(PUserNode currentUser){
    printf("\n--------------------------- 当前用户信息 --------------------------\n");
    printf("用户名: %s\n密码: %s\n", currentUser->info.username, currentUser->info.password);
    printf("按回车键继续\n");
    scanf("%*c");
}